<?php
include("./config.php");
include("./utils.php");
//checkLogin();
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>编辑</title>
  <?php include 'scripts-inc.php' ?>

  <script>
  var gData={};
  var gID = '<?php echo $_GET["id"]; ?>';
  var gUserID = '<?php echo $_GET["id"]; ?>';
  var gGeneration = 1;

  var get_data = function(id, generation, op){
    var u = 'query.php?op='+op+'&id='+id+'&generation='+generation;
    $.ajax({url:u,
      dataType:"json",
      async:true,
      success : function(msg, textStatus) {
        var data = msg[0];
        if(data){
          gGeneration = data["generation"];
          gID = data["id"];
          $("#tid").val(gID);
          $("#tname").val(data["name"]);
          $("#twife_name").val(data["wife_name"]);
          $("#tparentid").val(data["parentid"]);
          $("#tgeneration").val(data["generation"]);
          $("#tsex").val(data["sex"]);
          $("#tnote").val(data["note"]);
          $("#taddr").val(data["addr"]);
          $("#tborn_time").val(data["born_time"]);
          $("#tdie_time").val(data["die_time"]);
          $("#twife_born_time").val(data["wife_born_time"]);
          $("#twife_die_time").val(data["wife_die_time"]);
          $("#twife_addr").val(data["wife_addr"]);

          $(document).attr("title",'编辑[' + data['id']+data['name']+']');//修改title值
          $("#goback").attr("href","./show.php?"+"&id="+gID);
          gData = data;
        }
      }
    },"text");
  }
  $(function(){
    get_data(gID, 0, 'one');

    function updateOp(op, v){
      var data = {
        id:gID,
        op:op,
        value:v
      };

      show_msg("#content", "提交中...");
      $.post("update-data.php", data, function(msg){
        show_msg("#content", "修改完成");
      });
    }

    $("#save-parentid").click(function(){
      updateOp("save-parentid", $("#tparentid").val());
    });
    $("#save-geneation").click(function(){
      updateOp("save-geneation", $("#tgeneation").val());
    });
    $("#save-name").click(function(){
      updateOp("save-name", $("#tname").val());
    });
    $("#save-note").click(function(){
      updateOp("save-note", $("#tnote").val());
    });
    $("#save-addr").click(function(){
      updateOp("save-addr", $("#taddr").val());
    });
    $("#save-sex").click(function(){
      updateOp("save-sex", $("#tsex").val());
    });
    $("#save-born-time").click(function(){
      updateOp("save-born-time", $("#tborn-time").val());
    });
    $("#save-die-time").click(function(){
      updateOp("save-die-time", $("#tdie_time").val());
    });

    $("#save-wife-name").click(function(){
      updateOp("save-wife-name", $("#twife_name").val());
    });
    $("#save-wife-born-time").click(function(){
      updateOp("save-wife-born-time", $("#twife_born_time").val());
    });
    $("#save-wife-die-time").click(function(){
      updateOp("save-wife-die-time", $("#twife_die_time").val());
    });
    $("#save-wife-addr").click(function(){
      updateOp("save-wife-addr", $("#twife_addr").val());
    });



    $("#next-one").click(function(){
      get_data(gID, gGeneration, 'next-one');
    });
    $("#prev-one").click(function(){
      get_data(gID, gGeneration, 'prev-one');
    });
    addListeners();

  });//end of $(function(){

  </script>
</head>
<body>
<!-- template -->
<!-- end of template -->


<div id="wrapper">
<div id="container">
<!-- .................................................... -->

<div id="nav_data_src">
    <?php include 'navbars-inc.php' ?>
</div>

<div id="tcontainer" class="center">
<div class="container-fluid">
    <div class="form-group row">
      <label for="tid" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">ID</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tid" name="tid" placeholder="" disabled/>
      </div>
      <a href="javascript:window.opener=null;window.open('','_self');window.close();"
       class="lang-close btn btn-danger col-xs-2 col-sm-1 col-md-1 col-lg-1 text-center" 
       id="" >关闭</a>
    </div>

    <div class="form-group row">
      <label for="tparentid" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">父辈ID</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tparentid" name="tparentid" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-parentid">保存</button>
    </div>

    <div class="form-group row">
      <label for="tgeneration" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">代数</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tgeneration" name="tgeneration" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-generation">保存</button>
    </div>

    <div class="form-group row">
      <label for="tname" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">姓名</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tname" name="tname" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-name">保存</button>
    </div>

    <div class="form-group row">
      <label for="tsex" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">性别</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tsex" name="tsex" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-sex">保存</button>
    </div>

    <div class="form-group row">
      <label for="tborn_time" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">降生时间</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tborn_time" name="tborn_time" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-born-time">保存</button>
    </div>

    <div class="form-group row">
      <label for="tdie_time" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">仙逝时间</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tdie_time" name="tdie_time" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-die-time">保存</button>
    </div>

    <div class="form-group row">
      <label for="taddr" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">地址</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="taddr" name="taddr" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-addr">保存</button>
    </div>

    <div class="form-group row">
      <label for="twife_name" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">配偶姓名</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="twife_name" name="twife_name" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-wife-name">保存</button>
    </div>
    
    <div class="form-group row">
      <label for="twife_die_time" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">配偶仙逝时间</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="twife_die_time" name="twife_die_time" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-wife-die-time">保存</button>
    </div>

    <div class="form-group row">
      <label for="twife_born_time" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">配偶降生时间</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="twife_born_time" name="twife_born_time" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-wife-die-time">保存</button>
    </div>


    <div class="form-group row">
      <label for="twife_addr" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">配偶地址</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="twife_addr" name="twife_addr" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-wife-addr">保存</button>
    </div>

    <div class="form-group row">
      <label for="tnote" class="col-xs-3 col-sm-2 col-md-2 col-lg-1 control-label">说明</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <textarea class="form-control" id="tnote" rows="3" name="tnote" placeholder=""></textarea>
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-note">保存</button>
    </div>

  <div class="clearfix"></div>
  <div class="form-group row">
      <button id="prev-one" href="#" class="btn btn-lg btn-default col-xs-2 col-sm-1 col-md-1 col-lg-1 text-center" >&lt;&lt;</button>
      <a href="./index.php" class="lang-return-keyboard btn btn-lg btn-default col-xs-4 col-sm-2 col-md-2 col-lg-2 text-center" id="goback" >返回家谱</a>
      <a href="./index.php" class="btn btn-lg btn-warning col-xs-4 col-sm-2 col-md-2 col-lg-2 text-center" id="goback-home" >返回主页</a>
      <button id="next-one" href="#" class="btn btn-lg btn-success col-xs-2 col-sm-2 col-md-2 col-lg-2 text-center" >&gt;&gt;</button>
  </div>
<div class="form-group row">
    <div class="col-xs-8 col-sm-3 col-md-3 col-lg-3 text-center">
      <div id="content"></div>
    </div>
</div>
</div>


</div> <!-- end of tcontainer -->

<!-- .................................................... -->
</div><!-- end of container -->
</div><!-- end of wrapper -->
</body>
</html>
